package com.jtf;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Screen;
import javafx.stage.Stage;
import org.w3c.dom.Document;
import org.w3c.dom.Element;


/**
 * JavaFX App
 */
public class App extends Application {

    private static Scene scene;

    public static void main(String[] args) {
        launch(args);
    }

    public void start(Stage primaryStage) {
        primaryStage.setTitle("吉利中石化大屏展示平台");

        WebView webView = new WebView();

        StackPane root = new StackPane();
        WebEngine engine = webView.getEngine();
        engine.load("https://www.baidu.com");
        Document document = engine.getDocument();

        root.getChildren().add(webView);
        Scene scene = new Scene(root);
        primaryStage.setScene(scene);
        primaryStage.show();
        primaryStage.setWidth(Screen.getPrimary().getVisualBounds().getWidth());
        primaryStage.setHeight(Screen.getPrimary().getVisualBounds().getHeight());
        primaryStage.setFullScreen(true);

        // 全屏监听器
        primaryStage.fullScreenProperty().addListener(new ChangeListener<Boolean>() {
            @Override
            public void changed(ObservableValue<? extends Boolean> prop, Boolean oldVal, Boolean newVal) {
                if(oldVal){
                    Platform.runLater(()->{
                        primaryStage.setWidth(Screen.getPrimary().getVisualBounds().getWidth());
                        primaryStage.setHeight(Screen.getPrimary().getVisualBounds().getHeight());
                    });
                }
            }
        });
        // 最大化按钮监听
        primaryStage.maximizedProperty().addListener(new ChangeListener<Boolean>() {
            @Override
            public void changed(ObservableValue<? extends Boolean> prop, Boolean oldVal, Boolean newVal) {
                Platform.runLater(()->{
                    primaryStage.setFullScreen(true);
                });
            }
        });
    }



}
